$(document).ready(function(){
	
	getCurrent(1,10);
	
	$('#firstPage').click(function(){		
		var page=1;
		var maxRow=$("#maxRow").text();
		getCurrent(1,maxRow);
	});
	
	$('#prePage').click(function(){		
		var page=$("#page").text();
		page=(parseInt(page)-1);
		var maxRow=$("#maxRow").text();
		if(page<=0){
			alert("第一页了");
			return ;
		}
		getCurrent(page,maxRow);
	});
	
	$('#nextPage').click(function(){		
		var page=$("#page").text();
		page=(parseInt(page)+1);
		var maxRow=$("#maxRow").text();
		var pageCount=$("#pageCount").text();
		if(page>=pageCount){
			alert("最后一页了");
			return;
		}
		getCurrent(page,maxRow);
	});
	
	$('#lastPage').click(function(){		
		var page=$("#pageCount").text();
		var maxRow=$("#maxRow").text();
		getCurrent(page,maxRow);
	});
	
	$('#jumpPage').click(function(){		
		var pageCount=$("#pageCount").text();
		var maxRow=$("#maxRow").text();
		var page=$("#jump").val();
		if(page>pageCount){
			alert("页数过大");
			return;
		}
		getCurrent(page,maxRow);
	});

});

	function getCurrent(page1,maxRow1){
		var page = page1;
		var maxRow = maxRow1;
		var gtID=$(window.parent.frames["topFrame"].document).find("#gtID option:selected").val();
		var gName=$(window.parent.frames["topFrame"].document).find("#gNameID").val();
		
		$('#wuzhiBody').empty();
		$("#loadingPerson").show();
		$.ajax({
  			type: "post",
 			url: "hmk/findSomeGoods_findGoodsList.action",
 			data:{
 				  gtypeID1:gtID,gName1:gName,page:page,maxRow:maxRow
 				 },
  			success:showData
		});
	}
	
	function getWuzhidetail(v){
		var gID = $(v).next().text();
		window.location.href="/ag/hmk/findSomeGoods_findOneGood.action?gID="+gID; //+"&findType1=1";
	}

	//删除物资
	function delwuzhi(v){
		var isPass = confirm("确定要删除吗？");
		if(isPass){
			var gID = $(v).next().text();
			var url = 'hmk/delGoods_delGood.action';
			var params = {
				gID:gID
			}; 
			jQuery.post(url, params, delData, 'json');
		}
	}

	function delData(data){
		if(data.delStr=='1'){
			alert("删除成功");
			var page=$("#page").text();
			getCurrent(page,10);
	 	}else{
			alert("删除失败");
		 }
}

	function showData(data){
		$('#wuzhiBody').empty();	
		if(data.pageUtil.list.length==0){
			$("#loadingPerson").hide();
			$("#nonePerson").show();
			$("#total").text(0);
			$("#page").text(0);
			$("#pageCount").text(0);
			$("#maxRow").text(0);
		}else{
			$("#nonePerson").hide();
		    $("#loadingPerson").hide();
		    $.each(data.pageUtil.list,function(i,n){
		    	var gt = n.tbGoodstype;
		    	if(gt==null){
		    		gt="";
		    	}else{
		    		gt=n.tbGoodstype.gtName;
		    	}
				fillDataToHtml(n.goodsId,gt,n.goodsName,n.tbUnit.unitName,
						  n.goodsDetail,data.gkuList[i]);
		  	});
		
		$('#total').text(data.pageUtil.total);
		$('#page').text(data.pageUtil.page);
		$('#pageCount').text(Math.ceil(data.pageUtil.total/10));
		$('#maxRow').text(data.pageUtil.maxRow);
		}
	}
	
	
	function fillDataToHtml(gid,gtype,gname,gunit,gdetail,akuList){
		var strHtml="<tr>";
		strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=gtype+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=gname+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=gunit+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=gdetail+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center' class='STYLE2 STYLE1'>";
        strHtml+=akuList+"</div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center'><img src='hmk/images/037.gif' width='9' height='9' /><span class='STYLE1'> [</span><a style='cursor:pointer' onclick='getWuzhidetail(this)'>详情</a>";
        	strHtml+="<span  style='display:none'>";
	    	strHtml+=gid;
	    	strHtml+="</span>";
        strHtml+="<span class='STYLE1'>]</span></div></td>";
        strHtml+="<td height='30px' bgcolor='#FFFFFF'><div align='center'><span class='STYLE2'><img src='hmk/images/010.gif' width='9' height='9' /> </span><span class='STYLE1'>[</span><a style='cursor:pointer' onclick='delwuzhi(this)'>删除</a>";
        	strHtml+="<span id='cID' style='display:none'>";
	    	strHtml+=gid;
	    	strHtml+="</span>";
        strHtml+="<span class='STYLE1'>]</span></div></td>"
        strHtml+="</tr>";
        
        $('#wuzhiBody').append(strHtml);
	}
	

